package com.zatom.newscore.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zatom.newscore.utils.U;
import javax.annotation.Resource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
public class BeanConfig implements CommandLineRunner {
  private static final Logger log = LogManager.getLogger(com.zatom.newscore.config.BeanConfig.class);
  
  @Lazy
  @Resource
  private RequestMappingHandlerMapping requestMappingHandlerMapping;
  
  public void run(String... args) throws Exception {
    this.requestMappingHandlerMapping.getHandlerMethods().forEach((k, v) -> log.info("HandlerMethods|" + k + " -> " + v.toString()));
  }
  
  @Bean
  @Primary
  public ObjectMapper jsonConverter() {
    return U.objectMapper;
  }
}
